package com.pangyangyang.elasticsearch.plugin.jdbc;

import java.util.regex.Pattern;

/**
 * Created by yangwang on 2015/1/21.
 */
public enum  PreparedStmtDataType {

//    Boolean(),
    Date("datetime", "date"),
//    Double(""),
//    Float,
//    Int,
//    Long,
    String("char", "varchar", "blob", "text", "float", "real", "double", "precision", "numeric", "decimal", "tinyint", "smallint", "mediumint", "integer", "bigint"),
//    Short,
//    Time,
    Timestamp("time", "timestamp");

    PreparedStmtDataType(String... dbType) {
        this.dbType = dbType;
    }

    private String[] dbType;
    private static Pattern typeRegex = Pattern.compile("(\\w+)");

    public static PreparedStmtDataType getFromDBType(String type){

        String typeLowCase = type.toLowerCase();
        for (PreparedStmtDataType stmtDataType : PreparedStmtDataType.values()){
            for (String stmtType : stmtDataType.dbType){
                if (stmtType.equals(typeLowCase)){
                    return stmtDataType;
                }
            }
        }
        return null;
    }
}
